home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / ean / ean2mmdf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  5.6 KB  |  307 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3.  
  4. /* Copyright University College London - 1984 */
  5.  
  6. /*
  7.  *  Steve Kille - November 1984
  8.  *
  9.  *  Routine to pass a message from EAN to MMDF
  10.  *
  11.  *  Usage  ean2mmdf -f sender dest dest .....
  12.  */
  13.  
  14. extern char *supportaddr;
  15. extern char *mmdflogin;
  16. extern LLog *logptr;
  17.  
  18. char *submitargs = "vmtiean*";
  19. char *signature = "EAN to MMDF Agent";
  20.  
  21. char template[] = "/tmp/ean.XXXXXX";
  22. FILE  *newfp;
  23.  
  24. int infile;
  25. int  gotone;
  26.  
  27. main (argc, argv)
  28. int argc;
  29. char *argv[];
  30. {
  31.     char buf[BUFSIZ];
  32.     struct rp_bufstruct thereply;
  33.     int i;
  34.     int len;
  35.     int firstone;
  36.     char *sender;
  37.  
  38.  
  39.     mmdf_init (argv[0]);
  40.     siginit ();
  41.  
  42.     if (lexequ (argv[1], "-f"))
  43.     {
  44.         if (argc < 4)
  45.         {
  46.             ll_log (logptr, LLOGTMP, "Insufficient arguments");
  47.             exit (NOTOK);
  48.         }
  49.         sender = argv[2];
  50.         firstone = 3;
  51.     }
  52.     else
  53.     {
  54.         if (argc < 2)
  55.         {
  56.             ll_log (logptr, LLOGTMP, "Insufficient arguments");
  57.             exit (NOTOK);
  58.         }
  59.         sender = supportaddr;
  60.         firstone = 1;
  61.     }
  62.  
  63.  
  64.     ll_log (logptr, LLOGFST, "EAN message from '%s'", sender);
  65.  
  66.     infile = FALSE;
  67.  
  68.  
  69.     if (rp_isbad (mm_init ()) || rp_isbad (mm_sbinit()))
  70.     {
  71.         ll_log (logptr, LLOGTMP, "Failed to start submit");
  72.         byebye (NOTOK);
  73.     }
  74.  
  75.     if (rp_isbad (mm_winit ((char *)0, submitargs, sender))
  76.       || rp_isbad (mm_rrply (&thereply, &len)))
  77.     {
  78.         ll_log (logptr, LLOGTMP, "Failed on mm_winit");
  79.         byebye (NOTOK);
  80.     }
  81.     switch (rp_gbval(thereply.rp_val)) {
  82.     case RP_BNO:
  83.     case RP_BTNO:
  84.         ll_log (logptr, LLOGTMP, "mm_winit reply RP_NO");
  85.         byebye (NOTOK);
  86.     }
  87.  
  88.     for (i = firstone; i < argc; i++)
  89.         do_adr (sender, argv[i]);
  90.  
  91.  
  92.     if (!gotone)
  93.     {
  94.         ll_log (logptr, LLOGBST, "No valid addresses");
  95.         byebye (OK);
  96.     }
  97.  
  98.     if (rp_isbad (mm_waend ()))
  99.     {
  100.         ll_log (logptr, LLOGTMP, "Failed on mm_waend");
  101.         byebye (NOTOK);
  102.     }
  103.  
  104.  
  105.             /* If Strat of messsage is in file, get it */
  106.     if (infile)
  107.     {
  108.         while ((i = fread(buf, sizeof(char), sizeof buf, newfp))
  109.             != NULL)
  110.         {
  111.             if (rp_isbad (mm_wtxt (buf, i)))
  112.             {
  113.                 ll_log (logptr, LLOGTMP, "Failed on mm_wtxt");
  114.                 byebye (NOTOK);
  115.             }
  116.         }
  117.     }
  118.  
  119.  
  120.     while ((i = fread(buf, sizeof(char), sizeof buf, stdin)) != NULL)
  121.     {
  122.         if (rp_isbad (mm_wtxt (buf, i)))
  123.         {
  124.             ll_log (logptr, LLOGTMP, "Failed on mm_wtxt");
  125.             byebye (NOTOK);
  126.         }
  127.     }
  128.  
  129.     if (rp_isbad (mm_wtend ()))
  130.     {
  131.         ll_log (logptr, LLOGTMP, "Failed on mm_wtend");
  132.         byebye (NOTOK);
  133.     }
  134.  
  135.     if (rp_isbad (mm_rrply (&thereply, &len)))
  136.     {
  137.         ll_log (logptr, LLOGTMP, "Failed on mm_rrply");
  138.         byebye (NOTOK);
  139.     }
  140.  
  141.  
  142.     if (rp_isbad (thereply.rp_val))
  143.     {
  144.         ll_log (logptr, LLOGTMP, "Bad reply value (%s) '%s'",
  145.             rp_valstr (thereply.rp_val), thereply.rp_line);
  146.         byebye (NOTOK);
  147.     }
  148.  
  149.  
  150.     if (rp_isbad (mm_sbend ()))
  151.     {
  152.         ll_log (logptr, LLOGTMP, "Failed on mm_sbend");
  153.         byebye (NOTOK);
  154.     }
  155.  
  156.     ll_log (logptr, LLOGFST, "Mail success  from EAN to MMDF");
  157.  
  158.     byebye (OK);
  159. }
  160. /*  */
  161.  
  162.                 /* process one address                  */
  163. do_adr (sender, adr)
  164. char *sender;
  165. char *adr;
  166. {
  167.     int retval;
  168.     struct rp_bufstruct thereply;
  169.     int len;
  170.  
  171.  
  172.     ll_log (logptr, LLOGFST, "EAN doing address  (%s)", adr);
  173.  
  174.  
  175.     if (rp_isbad (retval = mm_wadr ("", adr)) ||
  176.         rp_isbad (retval = mm_rrply (&thereply, &len)))
  177.     {
  178.         ll_log (logptr, LLOGTMP, "Failed to write adr '%s' for reason '%s'",
  179.             adr, rp_valstr (retval));
  180.         byebye (NOTOK);
  181.     }
  182.     switch (rp_gval (thereply.rp_val))
  183.     {
  184.         case RP_AOK:
  185.             ll_log (logptr, LLOGFST, "Good address %s",
  186.                     adr);
  187.             gotone = TRUE;
  188.             break;
  189.         case RP_DOK:
  190.             ll_log (logptr, LLOGFST, "Possibly good address %s",
  191.                     adr);
  192.             gotone = TRUE;
  193.             break;
  194.         default:
  195.             ll_log (logptr, LLOGBST, "Bad address '%s' [%s] %s",
  196.                 adr, rp_valstr (thereply.rp_val),
  197.                 thereply.rp_line);
  198.  
  199.             if (!infile)
  200.             {
  201.                     /* put citatin into file */
  202.                 getcite ();
  203.                 infile = TRUE;
  204.             }
  205.  
  206.             ml_1adr (TRUE, FALSE, signature,
  207.                 "Failed Mail Transfer", sender);
  208.             ml_txt ("Message not delivered to address: ");
  209.             ml_txt (adr);
  210.             ml_txt ("\n\nThe reason for the failure was:\n    [");
  211.             ml_txt (rp_valstr (thereply.rp_val));
  212.             ml_txt ("] ");
  213.             ml_txt (thereply.rp_line);
  214.             ml_txt ("\n\nYour Message begins as follows: \n\n");
  215.             ml_file (newfp);
  216.             fseek (newfp, 0L, 0);
  217.             ml_txt ("\n.......\n");
  218.             if (ml_end (OK) == OK)
  219.             {
  220.                  ll_log (logptr, LLOGFST, "Sent error to '%s'",
  221.                     sender);
  222.                  break;
  223.             }
  224.  
  225.                  ll_log (logptr, LLOGTMP, "Failed to send warning to '%s'", sender);
  226.  
  227.                     /* Now try support */
  228.             ml_1adr (TRUE, FALSE, signature,
  229.                 "Failed Mail Transfer", supportaddr);
  230.             ml_txt ("Message not delivered to address: ");
  231.             ml_txt (sender);
  232.             ml_txt ("\n\n Failure message for transfer to adr: ");
  233.             ml_txt (adr);
  234.             ml_txt ("\n\nThe reason for the failure was:\n  [");
  235.             ml_txt (rp_valstr (thereply.rp_val));
  236.             ml_txt ("] ");
  237.             ml_txt (thereply.rp_line);
  238.             ml_txt ("\n\nMessage begins a follows: \n\n");
  239.             ml_file (newfp);
  240.             fseek (newfp, 0L, 0);
  241.             ml_txt ("\n.......\n");
  242.             if (ml_end (OK) != OK)
  243.  
  244.                  ll_log (logptr, LLOGTMP, "Failed to send warning to '%s'", supportaddr);
  245.             else
  246.                   ll_log (logptr, LLOGFST, "Sent error report to '%s'",
  247.                 supportaddr);
  248.             break;
  249.     }
  250. }
  251.  
  252.  
  253. /*  */
  254.  
  255. getcite()
  256. {
  257.     char buf[LINESIZE];
  258.     int i;
  259.  
  260.     file_init();
  261.     i =0;
  262.     while (fgets (buf, LINESIZE, stdin) != NULL)
  263.     {
  264.         fputs (buf, newfp);
  265.         if (strlen (buf) > 2)
  266.             i++;
  267.         if (i > 300)
  268.             break;
  269.     }
  270.     fclose (newfp);
  271.     if ((newfp =  fopen (template, "r")) == NULL)
  272.     {
  273.         ll_log (logptr, LLOGTMP, "failed to reopen template '%s'",
  274.             template);
  275.         byebye (NOTOK);
  276.     }
  277. }
  278.                 /* misc routines  */
  279. file_init ()
  280. {
  281.     int fd;
  282.  
  283.     mktemp (template);
  284.     if ((fd = creat (template, 0666)) < 0)
  285.     {
  286.         ll_log (logptr, LLOGTMP, "Failed to create temp file %s",
  287.             template);
  288.         exit (NOTOK);
  289.     }
  290.     newfp = fdopen (fd, "w");
  291. }
  292.  
  293. byebye (retval)
  294. int retval;
  295. {
  296.     if (infile)
  297.     {
  298.         fclose (newfp);
  299.         unlink (template);
  300.     }
  301.     if (retval  == OK)
  302.         mm_end (OK);
  303.     else
  304.         mm_end (NOTOK);
  305.     exit (retval);
  306. }
  307.